package com.woniuxy.action;

import java.io.File;
import java.util.Map;
import java.util.UUID;

import org.apache.struts2.interceptor.RequestAware;

import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport implements RequestAware{
	
	private File headPic;
	private String headPicFileName;
	private String headPicContenType;
	private Map<String, Object> request;
	public File getHeadPic() {
		return headPic;
	}
	public void setHeadPic(File headPic) {
		this.headPic = headPic;
	}
	public String getHeadPicFileName() {
		return headPicFileName;
	}
	public void setHeadPicFileName(String headPicFileName) {
		this.headPicFileName = headPicFileName;
	}
	public String getHeadPicContenType() {
		return headPicContenType;
	}
	public void setHeadPicContenType(String headPicContenType) {
		this.headPicContenType = headPicContenType;
	}
	
	@Override
	public String execute() throws Exception {
		//上传路径
		String path ="D:\\te\\Maven_Test\\Maven_Struts\\src\\main\\webapp\\img";
		//创建文件名
		String headPicContenType=this.headPicFileName.substring(headPicFileName.lastIndexOf(".")+1);
		String fileName = UUID.randomUUID().toString()+"."+headPicContenType;
		
		File file = new File(path,fileName);
		
		headPic.renameTo(file);
		
		request.put("result", "文件上传成功");
		request.put("fileName", fileName);
		return ERROR;
	}
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request = request;
	}
	
}
